﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace F1RacingGame
{
    public partial class Form1 : Form
    {
        private GameEngine gameEngine;
        
        public Form1()
        {
            InitializeComponent();
            
            // 启用双缓冲以减少闪烁
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | 
                         ControlStyles.UserPaint | 
                         ControlStyles.DoubleBuffer |
                         ControlStyles.ResizeRedraw |
                         ControlStyles.SupportsTransparentBackColor, true);
            
            // 禁用Windows的自动重绘
            this.UpdateStyles();
            
            // 初始化音效管理器
            SoundManager.Instance.Initialize();
            
            // 初始化游戏引擎
            gameEngine = new GameEngine(this);
            
            // 初始化游戏管理器
            GameManager.Instance.Initialize(gameEngine);
            
            // 设置窗体关闭事件
            this.FormClosing += Form1_FormClosing;
        }
        
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // 清理游戏资源
            gameEngine?.Dispose();
            SoundManager.Instance.Dispose();
        }
    }
}
